package cn.edu.sdjzu.xg2106.controller;

import cn.edu.sdjzu.exception.BysjException;
import cn.edu.sdjzu.xg2106.service.DepartmentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;


@WebServlet("/departmentDelete.ctl")
public class DepartmentDelete extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, IOException {
        //创建JSON对象，以便向前端响应信息
        String id_str = request.getParameter("id");
        int id = Integer.parseInt(id_str);
        try {
            DepartmentService.getInstance().delete(id);
            response.getWriter().println("删除成功");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }catch (BysjException e){
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
